#include <stdio.h>
#include <string.h>

struct Student {
    int gender;
    char name[9];
    int used;
};

int main() {
    int N;
    scanf("%d", &N);
    struct Student s[50];
    for (int i = 0; i < N; i++) {
        scanf("%d %s", &s[i].gender, s[i].name);
        s[i].used = 0;
    }
    for (int i = 0; i < N; i++) {
        if (s[i].used) continue;
        for (int j = N - 1; j > i; j--) {
            if (!s[j].used && s[i].gender != s[j].gender) {
                printf("%s %s\n", s[i].name, s[j].name);
                s[i].used = 1;
                s[j].used = 1;
                break;
            }
        }
    }
    return 0;
}
